package com.itheima.edu.info.manager.dao;

import com.itheima.edu.info.manager.domain.Teacher;

public class TeacherDao extends OtherStudentDao {
    static Teacher[] teacherArr = new Teacher[5];

    public boolean addTeacher(Teacher teacher) {
        for (int i = 0; i < teacherArr.length; i++) {
            Teacher teachers = teacherArr[i];
            if(teachers == null){
                teacherArr[i] = teacher;
                return true;
            }
        }
        return false;
    }

    public Teacher[] getTeacherArr() {
        return teacherArr;
    }

    public Teacher[] findAllTeacher() {
        return teacherArr;
    }

    public void deleteTeacherById(String id) {
        for (int i = 0; i < teacherArr.length; i++) {
            Teacher teacher = teacherArr[i];
            if(teacher != null && id.equals(teacher.getId())){
                teacherArr[i] = null;
            }
        }
    }

    public void updateTeacher(Teacher teacher, String id) {
        for (int i = 0; i < teacherArr.length; i++) {
            Teacher newTeacher = teacherArr[i];
            if(newTeacher != null && id.equals(newTeacher.getId())){
                teacherArr[i] = teacher;
            }
        }
    }
}
